//
//  MYXReleaseHistoryController.m
//  meiyinxiang
//
//  Created by lizidi on 2018/1/24.
//  Copyright © 2018年 hbjApple. All rights reserved.
//

#import "MYXReleaseHistoryController.h"
#import "MYXReleasePhotoViewCell.h"
#import "MYXcontentCell.h"

static NSString *const MYXReleasePhotoViewCellIdentifier = @"MYXReleasePhotoViewCell";
static NSString *const MYXcontentCellIdentifier = @"MYXcontentCell";

@interface MYXReleaseHistoryController ()<UITableViewDelegate,UITableViewDataSource>
{
    MYXReleasePhotoViewCell *MYXReleasePhotoViewCe ;
    MYXcontentCell *MYXcontentCe;
    
}

@property(nonatomic, strong)UITableView *tableView;
@property (nonatomic,strong)UISegmentedControl * topCtrl;


@end

@implementation MYXReleaseHistoryController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
    
}
- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -SafeAreaTopHeight, WIDTH, HEIGHT+20) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        WS(weakSelf)
        //        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //            [weakSelf loadNewData];
        //        }];
        
        //        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //            [weakSelf loadMorewData];        }];
        
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createView];
}
-(void)createView{
    
    UIView * topView =[[UIView alloc]init];
    topView.backgroundColor = RGBACOLOR(232, 80, 77, 1);
    [self.view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(0);
        make.height.offset([MyAdapter laDapter:74]);
    }];
    UIButton * backBtn =[[UIButton alloc]init];
    [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset([MyAdapter laDapter:15]);
        make.width.height.offset([MyAdapter laDapter:24]);
        make.centerY.equalTo(topView.mas_centerY);
    }];
    _topCtrl = [[UISegmentedControl alloc] initWithItems:@[@"发布的红包",@"抢到的红包"]];
    _topCtrl.tintColor = [UIColor whiteColor];
    _topCtrl.selectedSegmentIndex = 0;
    UIFont *font = [UIFont boldSystemFontOfSize:16.0f];
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
                                                           forKey:UITextAttributeFont];
    [_topCtrl setTitleTextAttributes:attributes
                            forState:UIControlStateNormal];
    [topView addSubview:_topCtrl];
    [_topCtrl addTarget:self action:@selector(changeIndex:) forControlEvents:UIControlEventValueChanged];
    [_topCtrl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset([MyAdapter laDapter:40]);
        make.centerX.equalTo(topView.mas_centerX);
        make.centerY.equalTo(topView.mas_centerY).offset([MyAdapter laDapter:10]);
        make.width.offset(ScreenWidth/2);
    }];
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(topView.mas_bottom).offset(0);
        make.height.offset(ScreenHeight-[MyAdapter laDapter:74]);
    }];
    [self.tableView registerNib:[UINib nibWithNibName:MYXReleasePhotoViewCellIdentifier bundle:nil] forCellReuseIdentifier:MYXReleasePhotoViewCellIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:MYXcontentCellIdentifier bundle:nil] forCellReuseIdentifier:MYXcontentCellIdentifier];
}
-(void)goBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)changeIndex:(UISegmentedControl *)ctrl{
    //    for (UIView * vv in self.view.subviews) {
    //        if (![vv isKindOfClass:[UISegmentedControl class]]) {
    //            [vv removeFromSuperview];
    //        }
    //    }
    
    if (ctrl.selectedSegmentIndex==0) {
        NSLog(@"1111");
    }else{
        NSLog(@"2222");
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MYXReleasePhotoViewCe = [tableView dequeueReusableCellWithIdentifier:MYXReleasePhotoViewCellIdentifier forIndexPath:indexPath];
    MYXReleasePhotoViewCe.selectionStyle = UITableViewCellSelectionStyleNone;
    //MYXReleasePhotoViewCe.MYXmypublishMo = MYXmypublishMo;
    return MYXReleasePhotoViewCe;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

